Skip to content

fix: correct control flow bugs in reportit() and check_logic()#46

Draft
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-control-flow-bugs
Draft

fix: correct control flow bugs in reportit() and check_logic()#46
toddr-bot wants to merge 1 commit into
mainfrom
koan.toddr.bot/fix-control-flow-bugs

Conversation

@toddr-bot

@toddr-bot toddr-bot commented Apr 5, 2026

Copy link
Copy Markdown
Contributor

What

Fix three categories of control flow bugs in Agent.pm and Core.pm.

Why

  • reportit() used exit() where checkit() uses return() for identical cases (printhash, simulate, no objects). This terminates the process instead of returning a status code, breaking library consumers like SpamAssassin.
  • check_logic() used next inside a subroutine called from a loop — deprecated behavior that produces "Exiting subroutine via next" warnings under use warnings.
  • Core.pm used string eq for numeric length comparisons.

How

  • Replaced exit 0/exit 1 with return 1 in reportit(), matching checkit()'s convention (0=spam, 1=ok, 2=error).
  • Replaced next with return in check_logic() — the early return after setting spam=0 is the correct behavior for skipped objects.
  • Changed $clen eq 0 and $clen eq $olen to use ==.

Testing

  • Added t/control_flow.t with 4 subtests covering all fixed paths.
  • Full suite: 186 tests pass.

🤖 Generated with Claude Code


Quality Report

Changes: 4 files changed, 132 insertions(+), 8 deletions(-)

Code scan: clean

Tests: passed (OK)

Branch hygiene: clean

Generated by Kōan post-mission quality pipeline

- Replace exit() with return in reportit() for printhash, simulate, and
  empty-objects cases. checkit() already uses return for identical cases;
  the exit() calls prevented proper return code handling and broke library
  usage (e.g. SpamAssassin integration).
- Replace next with return in check_logic(), which is a subroutine called
  from a loop — next in a sub produces "Exiting subroutine via next"
  warnings and is deprecated behavior.
- Use numeric == instead of string eq for length comparisons in Core.pm
  preprocessing pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant